# datetime module
from datetime import datetime, timedelta, timezone
now = datetime.now()
print(now) # 2017-08-17 11:50:11.901403
dt = datetime(2017, 8, 17, 11, 50, 20)
print(dt) # 2017-08-17 11:50:20
tp = dt.timestamp()
print(tp) # 1502941820.0

dt = datetime.fromtimestamp(tp)
print(dt)

# str转换为datetime
cday = datetime.strptime('2015-6-1 18:19:59', '%Y-%m-%d %H:%M:%S')
print(cday)

# datetime转换为str
print(now.strftime('%a, %b %d %H:%M'))

# datetime加减
print(now + timedelta(hours=4)) # 2017-08-17 15:57:25.715009

# 本地时间转换为UTC时间
# 本地时间是指系统设定时区的时间，例如北京时间是UTC+8:00时区的时间，而UTC时间指UTC+0:00时区的时间。

